home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / gameboy / lame.h < prev    next >
C/C++ Source or Header  |  1995-12-30  |  2KB  |  101 lines

  1. /** VGB: portable GameBoy emulator ***************************/
  2. /**                                                         **/
  3. /**                          Lame.h                         **/
  4. /**                                                         **/
  5. /** This file is compiled when LAME id #defined. It         **/
  6. /** contains simplified Z80 engine.                         **/
  7. /**                                                         **/
  8. /** Copyright (C) Marat Fayzullin 1994,1995                 **/
  9. /**     You are not allowed to distribute this software     **/
  10. /**     commercially. Please, notify me, if you make any    **/   
  11. /**     changes to this file.                               **/
  12. /*************************************************************/
  13.  
  14. void CodesCB(void)
  15. {
  16.   register byte I;
  17.  
  18.   switch(*(Addr+(R.PC.W++)))
  19.   {
  20. #include "CodesCB.h"
  21.     default:
  22.       if(TrapBadOps)
  23.         printf("Unrecognized CB instruction at PC=%hX\n",R.PC.W-2);
  24.   }
  25. }
  26.  
  27. void CodesED(void)
  28. {
  29.   register byte I;
  30.   register pair J;
  31.  
  32.   switch(*(Addr+(R.PC.W++)))
  33.   {
  34. #include "CodesED.h"
  35.     default:
  36.       if(TrapBadOps)
  37.         printf
  38.         (
  39.           "Unrecognized instruction: ED %X at PC=%hX\n",
  40.           *(Addr+R.PC.W-1),R.PC.W-2
  41.         );
  42.   }
  43. }
  44.  
  45. word Z80(register byte *A,reg Regs)
  46. {
  47.   register byte I;
  48.   register pair J;
  49.  
  50.   R=Regs;Addr=A;
  51.  
  52. #ifdef INTERRUPTS
  53.   Cnt=IPeriod;
  54. #endif
  55.   
  56.   for(CPURunning=1;CPURunning;)
  57.   {
  58.     LCDSTAT=(LCDSTAT&0xFC)|((Cnt>>5)&0x03);
  59.  
  60.     switch(*(Addr+(R.PC.W++)))
  61.     {
  62. #include "Codes.h"
  63.       case PFX_CB: CodesCB();break;
  64.       case PFX_ED: CodesED();break;
  65.       case 0x10:  
  66.       case HALT: 
  67. #ifdef INTERRUPTS
  68.         if(Cnt) R.PC.W--; else R.IFF|=0x01;
  69. #else   
  70.         printf("CPU HALTed and stuck at PC=%hX\n",--R.PC.W);
  71.         CPURunning=0;
  72. #endif
  73.         break;
  74.       default:
  75.         if(TrapBadOps)
  76.           printf("Unrecognized instruction at PC=%hX\n",R.PC.W-1);
  77.     }
  78.  
  79. #ifdef INTERRUPTS
  80.     if(!Cnt--) 
  81.     {
  82.       Cnt=IPeriod;
  83.       if(IntSync) IFlag=1;
  84.     }
  85.     if(IFlag)
  86.     {
  87.       IFlag=0;J.W=Interrupt();
  88.       if((J.W!=0xFFFF)&&(R.IFF&0x01))
  89.       { M_PUSH(PC);R.PC.W=R.IFF&0x04? ((word)R.I<<8)+0xFF:J.W; }
  90.     }  
  91. #endif
  92.  
  93. #ifdef DEBUG
  94.     if(R.PC.W==Trap) Trace=1;  /*** Turn tracing on if trapped ***/
  95.     if(Trace) Z80_Debug(Addr,R);   /*** Call single-step debugger  ***/
  96. #endif
  97.  
  98.   }
  99.   return(R.PC.W);
  100. }
  101.